package userlogic

import (
	"context"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/user"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddUserValidConsumeLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddUserValidConsumeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddUserValidConsumeLogic {
	return &AddUserValidConsumeLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// rpc declareRedEnvelope() returns ()
func (l *AddUserValidConsumeLogic) AddUserValidConsume(in *rpc.AddValidConsumeRequest) (*rpc.AddValidConsumeResponse, error) {
	walletModel := user.NewWalletModel(l.ctx, l.svcCtx.Db)
	_, err := walletModel.AddValidConsume(in.UserId, in.ValidConsume)
	if err != nil {
		return nil, err
	}

	cresp := &rpc.CommonResp{
		Code:    0,
		Message: "",
	}
	return &rpc.AddValidConsumeResponse{CommonResp: cresp}, nil
}
